import 'package:im_base/public/components/custom_picker_delegate.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import 'package:get/get.dart';

///@author:create by BZY
///Date: 2021/12/8 14:36
///Description:

///选择图片[maxNum] 最大选择数量
Future<List<AssetEntity>?> selectPhoto({int? maxNum}) async {
  final DefaultAssetPickerProvider provider = DefaultAssetPickerProvider(
    maxAssets: maxNum ?? 1,
    pageSize: 40,
    pathThumbSize: 80,
    requestType: RequestType.image,
    sortPathDelegate: CustomPickerDelegate(),
    routeDuration: const Duration(milliseconds: 300),
  );

  return await AssetPicker.pickAssetsWithDelegate(Get.context!,
      provider: provider,
      delegate: DefaultAssetPickerBuilderDelegate(
          provider: provider,
          specialItemPosition: SpecialItemPosition.none,
          initialPermission: await AssetPicker.permissionCheck()));
}

///选择图片[maxNum] 最大选择数量
Future<List<AssetEntity>?> selectVideo({int? maxNum}) async {
  final DefaultAssetPickerProvider provider = DefaultAssetPickerProvider(
    maxAssets: maxNum ?? 1,
    pageSize: 40,
    pathThumbSize: 80,
    filterOptions: FilterOptionGroup(
        videoOption: FilterOption(
            durationConstraint:
                DurationConstraint(max: const Duration(seconds: 30)))),
    requestType: RequestType.video,
    sortPathDelegate: CustomPickerDelegate(),
    routeDuration: const Duration(milliseconds: 300),
  );

  return await AssetPicker.pickAssetsWithDelegate(Get.context!,
      provider: provider,
      delegate: DefaultAssetPickerBuilderDelegate(
          provider: provider,
          specialItemPosition: SpecialItemPosition.none,
          initialPermission: await AssetPicker.permissionCheck()));
}
